package com.base.cn.platform.os.common.utils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * 输入流工具类
 *
 * @author s.li
 * @date 2019/05/29
 */
public class InputStreamUtil {

    /**
     * 读取流中的数据
     * @param inStream
     * @return
     * @throws Exception
     */
    public static byte[] readInputStream(InputStream inStream) throws Exception {
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = inStream.read(buffer)) != -1) {
            outStream.write(buffer, 0, len);
        }
        byte[] data = outStream.toByteArray();
        outStream.close();
        inStream.close();
        return data;
    }
}
